package com.netty.unit1nio.c2;

import com.netty.unit1nio.c1.ByteBufferUtil;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class client {
    public static void main(String[] args) throws IOException {
        SocketChannel sc=SocketChannel.open();//SocketChannel.open()是 创建一个SocketChannel对象，在操作系统层面是生成了一个 socket
   //建立连接，进行tcp三次握手
        sc.connect(new InetSocketAddress("localhost",8080));
        ByteBuffer buffer = ByteBuffer.allocate(16);
        buffer.put("hello".getBytes());
        buffer.flip();//切换到读模式
        sc.write(buffer);
        System.out.println("waiting...");
    }
}
